import { get, post, put, del } from '@/utils/request'

// 商品相关的类型定义
export interface Good {
  id?: number
  goodsCode?: string
  goodsName?: string
  bId?: number
  gtId?: number
  price?: number
  photo?: string
  state?: number
  remark?: string
  desc?: string
}

export interface GoodQueryParams {
  pageIndex: number
  pageSize: number
  name?: string
  category?: string
  status?: number
}

export interface GoodType {
  id: number
  goodsTypeName: string
}

export interface GoodResponse<T> {
  code: number
  msg: string
  data: {
    data: T
    totalCount: number
    totalPage: number
  }
}

// 获取商品列表
export const reqGoodList = (params: GoodQueryParams) => {
  return get<GoodResponse<Good[]>>('/api/Goods/GetGoodsNewList', params)
}

// 批量删除商品
export const reqDeleteGoods = (ids: string) => {
  return del<GoodResponse<number>>(`/api/Goods/DeleteAllGoods?ids=${ids}`)
}
//批量上下架
export const reqUpdateGoodState = (ids: string, state: boolean) => {
  return put<GoodResponse<number>>(
    `/api/Goods/UpdateAllState?ids=${ids}&state=${state}`
  )
}
// 获取雪花Id
export const reqSnowId = () => {
  return get<GoodResponse<string>>('/api/Goods/GetSnowId')
}
// 获取商品类型列表
export const reqGoodsTypesList = () => {
  return get<GoodResponse<GoodType[]>>('/api/Goods/GetGoodsTypesList')
}

// 创建及修改商品
export const reqCreateGood = (data: Good) => {
  return post<Good>('/api/Goods/GoodsAdd', data)
}

// 获取商品详情
export const reqGoodDetailById = (id: number) => {
  return get<GoodResponse<Good>>(`/api/Goods/GetGoods?id=${id}`)
}

//---------------------------------------------------------------------
// 获取商品详情
export const reqGoodDetail = (id: number) => {
  return get<Good>(`/api/goods/${id}`)
}

// 更新商品
export const updateGood = (id: number, data: Partial<Good>) => {
  return put<Good>(`/api/goods/${id}`, data)
}

// 删除商品
export const deleteGood = (id: number) => {
  return del<void>(`/api/goods/${id}`)
}

// 更新商品状态
export const updateGoodStatus = (id: number, status: number) => {
  return put<Good>(`/api/goods/${id}/status`, { status })
}

// 批量删除商品
export const batchDeleteGoods = (ids: number[]) => {
  return post<void>('/api/goods/batch-delete', { ids })
}

// 商品库存更新
export const updateGoodStock = (id: number, stock: number) => {
  return put<Good>(`/api/goods/${id}/stock`, { stock })
}

//  GET 请求示例
// const getData = async () => {
//   try {
//     const response = await get<YourResponseType>('/api/endpoint', {
//       param1: 'value1',
//     });
//     console.log(response);
//   } catch (error) {
//     console.error(error);
//   }
// };

//  POST 请求示例
// const postData = async () => {
//   try {
//     const response = await post<YourResponseType>('/api/endpoint', {
//       data: 'value',
//     });
//     console.log(response);
//   } catch (error) {
//     console.error(error);
//   }
// };
